﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="CreditCard.ascx.vb" Inherits="CreditCardPage" %>
<asp:UpdatePanel ID="upnlCardInfo" runat="server">
<ContentTemplate>
<div class="cardinfo">
<asp:Label ID="lblMyCustomerID" runat="server" Visible="false" />
<asp:Label ID="lblError" CssClass="validate" runat="server" />
<asp:DetailsView ID="dvCardInfo" runat="server" GridLines="Vertical" AutoGenerateRows="False" 
    Width="500px" FieldHeaderStyle-CssClass="tdright" RowStyle-CssClass="tdleft" 
    DataKeyNames="CardID" DataSourceID="adsCardInfo">
    <FieldHeaderStyle CssClass="tdright" />
    <Fields>
        <asp:BoundField DataField="CardID" HeaderText="CardID" 
            SortExpression="CardID" Visible="False" />
        <asp:TemplateField HeaderText="Card Type">
            <EditItemTemplate>
                <asp:DropDownList ID="ddlCardType" runat="server" 
                    SelectedValue='<%# Bind("CardType") %>'>
                    <asp:ListItem Value="" Text="[ -- Select -- ]" />
                    <asp:ListItem Value="MasterCard" />
                    <asp:ListItem Value="Visa" />
                    <asp:ListItem Value="American Express" />
                    <asp:ListItem Value="Discover" />
                </asp:DropDownList>
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="ddlCardType" ID="vldReqCardType" Display="None" runat="server" ErrorMessage="Select a card type" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqCardType_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqCardType" />
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:DropDownList ID="ddlCardType" runat="server" 
                    SelectedValue='<%# Bind("CardType") %>'>
                    <asp:ListItem Value="" Text="[ -- Select -- ]" />
                    <asp:ListItem Value="MasterCard" />
                    <asp:ListItem Value="Visa" />
                    <asp:ListItem Value="American Express" />
                    <asp:ListItem Value="Discover" />
                </asp:DropDownList>
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="ddlCardType" ID="vldReqCardType" Display="None" runat="server" ErrorMessage="Select a card type" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqCardType_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqCardType" />
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblCardType" runat="server" Text='<%# Bind("CardType") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Card Number" SortExpression="Card Number">
            <EditItemTemplate>
                <asp:TextBox ID="txtCardNumber" MaxLength="16" runat="server" Text='<%# Bind("CardNumber") %>'/>
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtCardNumber" ID="vldReqCardNumber" Display="None" runat="server" ErrorMessage="Card Number is required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqCardNumber_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqCardNumber" />
                <asp:CustomValidator ValidationGroup="CardInfo" ControlToValidate="txtCardNumber" Display="None" ID="vldCusCardNumber" runat="server" 
                    ErrorMessage="Enter a valid card" 
                    onservervalidate="vldCusCardNumber_ServerValidate" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldCusCardNumber_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldCusCardNumber" />
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtCardNumber" MaxLength="16" runat="server" Text='<%# Bind("CardNumber") %>'/>
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtCardNumber" ID="vldReqCardNumber" Display="None" runat="server" ErrorMessage="Card Number is required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqCardNumber_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqCardNumber" />
                <asp:CustomValidator ValidationGroup="CardInfo" ControlToValidate="txtCardNumber" Display="None" ID="vldCusCardNumber" runat="server" 
                    ErrorMessage="Enter a valid card" 
                    onservervalidate="vldCusCardNumber_ServerValidate" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldCusCardNumber_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldCusCardNumber" />
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblCardNum" runat="server" Text='<%# Bind("CardNumber") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Expiration Month" 
            SortExpression="ExpirationMonth">
            <EditItemTemplate>
                <asp:TextBox ID="txtExpireMonth" MaxLength="2" runat="server" Text='<%# Bind("ExpirationMonth") %>' />
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtExpireMonth" ID="vldReqExpireMonth" Display="None" runat="server" ErrorMessage="Expiration month required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqExpireMonth_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqExpireMonth"/>
                <asp:RangeValidator ValidationGroup="CardInfo" ControlToValidate="txtExpireMonth" ID="vldRangExpireMonth" Type="Integer" MinimumValue="1" MaximumValue="12" runat="server" Display="None" ErrorMessage="Enter a valid month" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldRangExpireMonth_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldRangExpireMonth"/>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtExpireMonth" MaxLength="2" runat="server" Text='<%# Bind("ExpirationMonth") %>' />
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtExpireMonth" ID="vldReqExpireMonth" Display="None" runat="server" ErrorMessage="Expiration month required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqExpireMonth_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqExpireMonth"/>
                <asp:RangeValidator ValidationGroup="CardInfo" ControlToValidate="txtExpireMonth" ID="vldRangExpireMonth" Type="Integer" MinimumValue="1" MaximumValue="12" runat="server" Display="None" ErrorMessage="Enter a valid month" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldRangExpireMonth_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldRangExpireMonth"/>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblExpireMonth" runat="server" Text='<%# Bind("ExpirationMonth") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Expiration Year" SortExpression="ExpirationYear">
            <EditItemTemplate>
                <asp:TextBox ID="txtExpireYear" MaxLength="4" runat="server" Text='<%# Bind("ExpirationYear") %>'/>
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtExpireYear" ID="vldReqExpireYear" Display="None" runat="server" ErrorMessage="Expiration year required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqExpireYear_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqExpireYear" />
                <asp:RangeValidator ValidationGroup="CardInfo" ControlToValidate="txtExpireYear" ID="vldRangExpireYear" Type="Integer" MinimumValue='<%# Now.Year %>' MaximumValue='<%# Now.Year+10 %>' runat="server" Display="None" ErrorMessage="Enter a valid expiration year" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldRangExpireYear_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldRangExpireYear" />
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtExpireYear" MaxLength="4" runat="server" Text='<%# Bind("ExpirationYear") %>'/>
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtExpireYear" ID="vldReqExpireYear" Display="None" runat="server" ErrorMessage="Expiration year required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqExpireYear_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqExpireYear" />
                <asp:RangeValidator ValidationGroup="CardInfo" ControlToValidate="txtExpireYear" ID="vldRangExpireYear" Type="Integer" MinimumValue='<%# Now.Year %>' MaximumValue='<%# Now.Year+10 %>' runat="server" Display="None" ErrorMessage="Enter a valid expiration year" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldRangExpireYear_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldRangExpireYear" />
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblExpireYear" runat="server" Text='<%# Bind("ExpirationYear") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Security Code" SortExpression="CVV">
            <EditItemTemplate>
                <asp:TextBox ID="txtCVV" MaxLength="4" runat="server" Text='<%# Bind("CVV") %>'/>
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtCVV" ID="vldReqCVV" Display="None" runat="server" ErrorMessage="Security Code required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqCVV_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqCVV" />
                <asp:CustomValidator ValidationGroup="CardInfo" ControlToValidate="txtCVV" Display="None" ID="vldCusCVV" runat="server" 
                    ErrorMessage="Enter a valid security code" onservervalidate="vldCusCVV_ServerValidate"  />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldCusCVV_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldCusCVV" />
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtCVV" MaxLength="4" runat="server" Text='<%# Bind("CVV") %>'/>
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtCVV" ID="vldReqCVV" Display="None" runat="server" ErrorMessage="Security Code required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqCVV_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqCVV" />
                <asp:CustomValidator ValidationGroup="CardInfo" ControlToValidate="txtCVV" Display="None" ID="vldCusCVV" runat="server" 
                    ErrorMessage="Enter a valid security code" onservervalidate="vldCusCVV_ServerValidate"  />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldCusCVV_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldCusCVV" />
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblCVV" runat="server" Text='<%# Bind("CVV") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Name on Card" SortExpression="NameOnCard">
            <EditItemTemplate>
                <asp:TextBox ID="txtName" MaxLength="50" runat="server" Text='<%# Bind("NameOnCard") %>' />
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtName" ID="vldReqName" Display="None" runat="server" ErrorMessage="Name is required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqName_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqName"/>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtName" MaxLength="50" runat="server" Text='<%# Bind("NameOnCard") %>' />
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtName" ID="vldReqName" Display="None" runat="server" ErrorMessage="Name is required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqName_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqName"/>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblName" runat="server" Text='<%# Bind("NameOnCard") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Postal Code" SortExpression="PostalCode">
            <EditItemTemplate>
                <asp:TextBox ID="txtPostalCode" MaxLength="15" runat="server" Text='<%# Bind("PostalCode") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtPostalCode" ID="vldReqPostalCode" runat="server" Display="None" ErrorMessage="Postal Code required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqPostalCode_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqPostalCode"/>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtPostalCode" MaxLength="15" runat="server" Text='<%# Bind("PostalCode") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ValidationGroup="CardInfo" ControlToValidate="txtPostalCode" ID="vldReqPostalCode" runat="server" Display="None" ErrorMessage="Postal Code required" />
                <ajaxToolkit:ValidatorCalloutExtender ID="vldReqPostalCode_ValidatorCalloutExtender" 
                    runat="server" Enabled="True" TargetControlID="vldReqPostalCode"/>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblPostalCode" runat="server" Text='<%# Bind("PostalCode") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" 
            SortExpression="CustomerID" Visible="False" />
    </Fields>
    <RowStyle CssClass="tdleft" />
</asp:DetailsView>
<asp:AccessDataSource ID="adsCardInfo" runat="server" 
    DataFile="~/App_Data/GotPink.accdb" 
    DeleteCommand="DELETE FROM [CustomerCards] WHERE [CardID] = ?" 
    InsertCommand="INSERT INTO [CustomerCards] ([CardType], [CardNumber], [ExpirationMonth], [ExpirationYear], [CVV], [NameOnCard], [PostalCode], [CustomerID]) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" 
    SelectCommand="SELECT [CardID], [CardType], [CardNumber], [ExpirationMonth], [ExpirationYear], [CVV], [NameOnCard], [PostalCode], [CustomerID] FROM [CustomerCards] WHERE ([CustomerID] = ?)" 
    UpdateCommand="UPDATE [CustomerCards] SET [CardType] = ?, [CardNumber] = ?, [ExpirationMonth] = ?, [ExpirationYear] = ?, [CVV] = ?, [NameOnCard] = ?, [PostalCode] = ?, [CustomerID] = ? WHERE [CardID] = ?">
    <InsertParameters>
        <asp:Parameter Name="CardType" Type="String" />
        <asp:Parameter Name="CardNumber" Type="String" />
        <asp:Parameter Name="ExpirationMonth" Type="Int32" />
        <asp:Parameter Name="ExpirationYear" Type="Int32" />
        <asp:Parameter Name="CVV" Type="Int32" />
        <asp:Parameter Name="NameOnCard" Type="String" />
        <asp:Parameter Name="PostalCode" Type="String" />
        <asp:ControlParameter ControlID="lblMyCustomerID" Name="CustomerID" PropertyName="Text" Type="Int32" />
    </InsertParameters>
    <SelectParameters>
        <asp:ControlParameter ControlID="lblMyCustomerID" Name="CustomerID" PropertyName="Text" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="CardType" Type="String" />
        <asp:Parameter Name="CardNumber" Type="String" />
        <asp:Parameter Name="ExpirationMonth" Type="Int32" />
        <asp:Parameter Name="ExpirationYear" Type="Int32" />
        <asp:Parameter Name="CVV" Type="Int32" />
        <asp:Parameter Name="NameOnCard" Type="String" />
        <asp:Parameter Name="PostalCode" Type="String" />
        <asp:ControlParameter ControlID="lblMyCustomerID" Name="CustomerID" PropertyName="Text" Type="Int32" />
        <asp:Parameter Name="CardID" Type="Int32" />
    </UpdateParameters>
</asp:AccessDataSource>
<br />
<asp:Button ValidationGroup="CardInfo" ID="btnSave" runat="server" Text="Add" />
</div>
</ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
